import BasicLayout from "@/layouts/BasicLayout.vue";
import { createRouter, createWebHashHistory } from "vue-router";
import Chat from "../views/Chat/Index.vue";
import BoardList from "../views/Employees/Board.vue";
import FundManage from "../views/Employees/FundManage.vue";
import EmployeeInfo from "../views/Employees/Info.vue";
import EmployeeList from "../views/Employees/List.vue";
import ScannerView from "../views/Employees/ScannerView.vue";
import SocialManage from "../views/Employees/SocialManage.vue";
import ScannerView1 from "../views/Employees/aa.vue";
import BackTuningManage from "../views/Employees/backTuningManage.vue";
import Home from "../views/Home.vue";
import LaborLibrary from "../views/LaborLibrary/Index.vue";
import Certify from "../views/MyEnterprise/Certify.vue";
import Certify1 from "../views/Signing/Certify.vue";
import MyEnterprise from "../views/MyEnterprise/Index.vue";
import PerCertify from "../views/PerCertify.vue";
import PerCertify1 from "../views/PerCertify1.vue";
import User from "../views/User/Index.vue";
import SigningCenter from "../views/Signing/index.vue";
import SigningCenterDetail from "../views/Signing/detail.vue";
import Regulations from "../views/Regulations/index.vue";
import Qianshu from "../views/Signing/qianshu.vue";
import Jieyue from "../views/Signing/jieyue.vue";
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: BasicLayout,
      redirect: "/home",
      children: [
        {
          path: "/home",
          name: "home",
          component: Home,
          meta: { title: "首页" },
        },
        {
          path: "/chat",
          name: "chat",
          component: Chat,
          meta: { title: "我的法务部" },
        },
        {
          path: "/myEnterprise",
          name: "myEnterprise",
          component: MyEnterprise,
          meta: { title: "我的企业" },
        },
        {
          path: "/laborLibrary",
          name: "laborLibrary",
          component: LaborLibrary,
          meta: { title: "劳动合规模板库" },
        },
        {
          path: "/myEnterprise/certify/",
          name: "certify",
          component: Certify,
          meta: { title: "企业认证" },
        },
        {
          path: "/perCertify",
          name: "perCertify",
          component: PerCertify,
          meta: { title: "个人认证" },
        },

        //三要素的
        {
          path: "/perCertifyThree",
          name: "perCertifyThree",
          component: PerCertify1,
          meta: { title: "个人认证" },
        },
        {
          path: "/certifyThree",
          name: "certifyThree",
          component: Certify1,
          meta: { title: "企业认证" },
        },
        {
          path: "/ScannerView",
          name: "ScannerView",
          component: ScannerView,
          meta: { title: "合规仪表盘" },
        },
        {
          path: "/aa",
          name: "aa",
          component: ScannerView1,
          meta: { title: "合规仪表盘1" },
        },
        {
          path: "/employee",
          name: "employee",
          redirect: "/employee/list",
          meta: { title: "员工管理" },
          children: [
            {
              path: "/employees/list",
              name: "employeeList",
              component: EmployeeList,
              meta: { title: "我的员工" },
            },
            {
              path: "/employees/board",
              name: "boardList",
              component: BoardList,
              meta: { title: "员工看板" },
            },
            {
              path: "/employees/socialManage",
              name: "socialManage",
              component: SocialManage,
              meta: { title: "社保管理" },
            },
            {
              path: "/employees/fundManage",
              name: "fundManage",
              component: FundManage,
              meta: { title: "公积金管理" },
            },
          ],
        },
        {
          path: "/backTuningManage",
          name: "backTuningManage",
          component: BackTuningManage,
          meta: { title: "在线背调" },
        },
        {
          path: "/employees/Info/:id/:name/:status",
          name: "employeeInfo",
          component: EmployeeInfo,
          meta: { title: "员工档案" },
        },
        {
          path: "/SigningCenter",
          name: "SigningCenter",
          component: SigningCenter,
          meta: { title: "签署中心" },
        },

        {
          path: "/qianshu/:task_id?/:name?/:status?/:userid?/:usertype?/:isDraft?",
          name: "qianshu",
          component: Qianshu,
          meta: { title: "签署" },
        },
        {
          path: "/jieyue/:task_id?/:userid?/:usertype?",
          name: "jieyue",
          component: Jieyue,
          meta: { title: "解约" },
        },
        {
          path: "/Regulations",
          name: "Regulations",
          component: Regulations,
          meta: { title: "规章制度" },
        },
        {
          path: "/user",
          name: "user",
          component: User,
          meta: { title: "个人中心" },
        },
        {
          path: "/SigningCenterDetail/:id?/:type?/:userId?/:usertype?",
          name: "SigningCenterDetail",
          component: SigningCenterDetail,
          meta: { title: "签署详情" },
        },
        {
          path: "/:pathMatch(.*)*",
          name: "404",
          component: () => import("../views/404.vue"),
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("../views/Login.vue"),
      meta: { title: "登录" },
    },

    {
      path: "/urldetail",
      name: "urldetail",
      component: () => import("../views/urldetail.vue"),
    },
    {
      path: "/pdfdetail",
      name: "pdfdetail",
      component: () => import("../views/pdfdetail.vue"),
    },
  ],
});

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("token");
  const whiteList = ["/login"];

  if (token) {
    if (to.path === "/login") {
      next({ path: "/home" });
    } else {
      next();
    }
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      next({
        path: "/login",
        query: { redirect: to.fullPath },
      });
    }
  }
});

export default router;
